package ss.pku.jsa.type.inference;

import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.IMethodBinding;

class MethodSig {
	String className;
	String methodName;
	String sig;

	public MethodSig(String className, String methodName, String sig) {
		this.className = className;
		this.methodName = methodName;
		this.sig = sig;
	}

	public MethodSig(IMethodBinding m) {
		IMethod im = (IMethod) m.getJavaElement();
		this.className = m.getDeclaringClass().getQualifiedName();
		this.methodName = m.getName();
		try {
			this.sig = im.getSignature();
			this.sig = "";
		} catch (JavaModelException e) {
			throw new IllegalArgumentException(e.toString());
		}
	}

	public int hashCode() {
		return this.className.hashCode() ^ this.methodName.hashCode()
				^ this.sig.hashCode();
	}

	public boolean equals(Object o) {
		if (!(o instanceof MethodSig))
			return false;
		MethodSig ms = (MethodSig) o;
		return (ms.className.equals(this.className))
				&& (ms.methodName.equals(this.methodName))
				&& (ms.sig.equals(this.sig));
	}

	public String toString() {
		return this.className + "." + this.methodName + "(" + this.sig + ")"
				+ hashCode();
	}
}
